<?php

namespace App\Models\Landscaping;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class ParkMessage extends Model
{
    use SoftDeletes;
    protected $guarded = [];
    //查询list
    public function getList($request)
    {
    	$per_page = $request->input('per_page',10);
    	return self::orderBy('id','desc')
                ->with('employees')
                ->where(function($query) use ($request){
                    //检测当前的请求中是否包含message_name、upload_id参数
                    $message_name = $request->input('message_name', '');//养护规程名
                    $upload_id = $request->input('upload_id','');//上传人
                    if(!empty($message_name)) {
                        $query->where('message_name','like','%'.$message_name.'%');
                    }
                    if(!empty($upload_id)) {
                        $query->where('upload_id','=',$upload_id);
                    }
                })
                ->paginate($per_page);
    }

    //查看上传人
    public function employees()
    {
        return $this->belongsTo(\App\Models\SystemManagement\Employee::class,'upload_id','id')->select('id','name');
    }
}
